package edu.chinasoft.servlet;

import edu.chinasoft.domain.Dept;
import edu.chinasoft.service.DeptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GetDeptForAddUserServlet",value = "/servlet/getdeptforadduserservlet")
public class GetDeptForAddUserServlet extends HttpServlet {
    private static Logger logger = LoggerFactory.getLogger(GetDeptForAddUserServlet.class);
    private DeptService deptService;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        DeptService deptServiceImp = wac.getBean("deptService", DeptService.class);
        this.deptService = deptServiceImp;
        List<Dept> deptList = deptService.selectDept();
        HttpSession session = request.getSession();
        session.setAttribute("deptInfo", deptList);

        response.sendRedirect(request.getContextPath() + "/addUser.jsp");
    }

}